def isPerfect(l):
    sum=0
    j=1
    while j>l:
        if l%j==0:
            sum += j
        j+=1
    if sum==l:
        return True
    else:
        return False

n=int(input())
max=n
min=n
if isPerfect(n):
    print(n)
while True:
    max+=1
    if isPerfect(max):
        print(max)
        break
    min-=1
    if isPerfect(min):
        print(min)
        break
